<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>竣工申请</title>
</head>

<body>
	<div class="content-container" data-options="region:'center'" title="竣工申请列表">
	<div class="panel-header"><div class="panel-title">竣工申请列表</div></div>
		<table id="pro_table" class="easyui-datagrid" style="height: 100%">
		</table>
	</div>

	<div style="display: none">
		<div id="displayAtt" class="datagrid-toolbar"
			style="width: 80%; max-height: 80%; padding: 5px; top: 30px; text-align: center;"></div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro;
	var projectitemid = [[${projectitemid}]];
	
	$(document).ready(function() {
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			url : "toapplyfinish.do?projectitemid="+projectitemid,
			method : 'get',
			onSelect : function(index, row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'title',
				title : '项目名',
				width : '',
				formatter : function(value,row,index) {
					if (row.item){
						return row.item.name;
					}
				}
			},{
				field : 'content',
				title : '摘要',
				width : ''
			},{
				field : 'status',
				title : '状态',
				width : '100px',
				formatter : function(value,row,index) {
					if (value == 2){
						return value = '进行中';
					}else if (value == 5){
						return value = '已竣工';
					}
				}
			},{
				field : 'attachment',
				title : '附件',
				width : '',
				formatter : function(value,row,index) {
					if (row.attachments.length > 0){
						return '<a href="#" style="color:red;" onclick="viewAtt(' + index + ');">点击查看</a>';
					}else{
						return '';
					}
				}
			} ] ]
		});
	});
	function viewAtt(index) {
		var row = $('#pro_table').datagrid('getRows')[index];
		var tb = "";
		$
				.each(
						row.attachments,
						function(i,val) {
							tb += '<div id="att'+val.id+'" class="col-md-3" ><a onclick="window.open(\''
									+ val.url
									+ '\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" alt="查看全图"><br>';
							tb += '<span>' + val.name + '</span><br>';
							tb += '<a href="javascript:void(0)" class="easyui-linkbutton l-btn" style="margin-right:3px;" onclick="attachmentFile('
									+ val.id + ',\'' + val.name + '\')"><span class="l-btn-text">下载</span></a>';
							tb += '</div>';
						});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
			title : '附件',
			resizable : true,
			closed : false,
			cache : false,
			modal : true
		});
	}
	function attachmentFile(id,name) {
		$.get('attachmentFile.do?id=' + id, function(data) {
			console.log(data);
			blob = new Blob([ data ])
			var a = document.createElement('a');
			a.download = name;
			a.href = window.URL.createObjectURL(blob)
			a.click()
		})
	}
</script>

</html>